﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.EquipmentManagement;
using Digitalmes.Model;



namespace Digitalmes.ViewModel.EquipmentManagement.ConsumableUsageVMs
{
    public partial class ConsumableUsageRecordDetailListVM : BasePagedListVM<ConsumableUsage, ConsumableUsageDetailSearcher>
    {
        
        protected override List<GridAction> InitGridAction()
        {
            return new List<GridAction>
            {
                this.MakeStandardAction("ConsumableUsage", GridActionStandardTypesEnum.AddRow, "新建","", dialogWidth: 800),
                this.MakeStandardAction("ConsumableUsage", GridActionStandardTypesEnum.RemoveRow, "删除","", dialogWidth: 800),
            };
        }
 
        protected override IEnumerable<IGridColumn<ConsumableUsage>> InitGridHeader()
        {
            return new List<GridColumn<ConsumableUsage>>{
                
                this.MakeGridHeader(x => x.MaterialId).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.耗材名称"].Value),
                this.MakeGridHeader(x => x.MaterialName).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.耗材名称"].Value),
                this.MakeGridHeader(x => x.Specification).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.规格"].Value),
                this.MakeGridHeader(x => x.Quantity).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.数量"].Value),
                this.MakeGridHeader(x => x.Unit).SetEditType(EditTypeEnum.TextBox).SetTitle(@Localizer["Page.单位"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ConsumableUsage> GetSearchQuery()
        {
                
            var id = (long?)Searcher.RecordId.ConvertValue(typeof(long?));
            if (id == null)
                return new List<ConsumableUsage>().AsQueryable().OrderBy(x => x.ID);
            var query = DC.Set<ConsumableUsage>()
                .Where(x => id == x.RecordId)

                .OrderBy(x => x.ID);
            return query;
        }

    }

    public partial class ConsumableUsageDetailSearcher : BaseSearcher
    {
        
        [Display(Name = "_Model._ConsumableUsage._Record")]
        public string RecordId { get; set; }
    }

}

